import 'package:flutter/material.dart';
import 'package:ost_flutter_module/common/adapt.dart';
import 'package:ost_flutter_module/common/color.dart';

class GTextButton extends StatelessWidget {
  final String title;
  final Widget child;
  final double fontSize;
  final Color normalForgroundColor;
  final Color pressedForgroundColor;
  final Color normalBackgroundColor;
  final Color pressedBackgroundColor;
  final bool isStadiumBorder;
  final double radius;
  final double padding;
  final VoidCallback onPressed;

  const GTextButton({
    Key key,
    this.title,
    this.fontSize = 14,
    this.normalForgroundColor = color999999,
    this.pressedForgroundColor,
    this.normalBackgroundColor,
    this.pressedBackgroundColor,
    this.isStadiumBorder = false,
    this.radius = 0,
    this.onPressed,
    this.child,
    this.padding,
  }) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return TextButton(
      onPressed: onPressed,
      child: child != null
          ? child
          : Text(
              title ?? '',
              style: TextStyle(fontSize: fontSize),
            ),
      // autofocus: true,
      style: ButtonStyle(
        foregroundColor: MaterialStateProperty.resolveWith((states) {
          if (states.contains(MaterialState.pressed)) {
            return pressedForgroundColor;
          }
          return normalForgroundColor ?? Colors.white;
        }),
        backgroundColor: MaterialStateProperty.resolveWith((states) {
          if (states.contains(MaterialState.pressed)) {
            return pressedBackgroundColor ??
                (normalBackgroundColor ?? color4DD1D1D1);
          }
          return normalBackgroundColor ?? null;
        }),
        padding: padding == null
            ? null
            : MaterialStateProperty.all(EdgeInsets.all(Adapt.px(padding))),
        shape: isStadiumBorder
            ? MaterialStateProperty.all(StadiumBorder())
            : MaterialStateProperty.all(RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(Adapt.px(radius)))),
      ),
    );
  }
}
